#include "student.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int student_init(struct student * p_student, 
        char *p_name, unsigned int id,
        char sex, float height, float weight,
        int (*student_self_introduction)(struct student *p_student))
{
    memcpy(p_student->name, p_name, strlen(p_name)); /*通过内存拷贝的方式*/

    p_student->id = id;
    p_student->sex = sex;
    p_student->height = height;
    p_student->weight = weight;
    p_student->student_self_introduction = student_self_introduction;

    return 0; 
}

int  student_self_introduction(struct student *p_this)
{
    printf("Hi! My name is %s, I'm a %s,  My school number is %d." 
            "My height is %fcm and weight is %fkg\n ", 
            p_this->name, 
            (p_this->sex = 'M') ? "boy" : "girl",
            p_this->id,
            p_this->height,
            p_this->weight);
    return 0;
}

int student_self_instroduction_zhansan(struct student *p_student)
{
    const char *str = "亲爱的老师，同学们，我叫张三，来自美丽的四川，今年 18 岁， "
        "是一个自信，开朗，友好，积极向上的人，我有着广泛的兴趣爱"
        "好，喜欢健身、打篮球、看书、下棋、听音乐，特别对主持和街"
        "舞有着浓厚的兴趣，希望能和同学们做好朋友，一起学习，一起"
        "玩耍……";

    printf("%s\n", str);

    return 0;
}



int main(void)
{
    struct student students[2];

    student_init(&students[0], "张三", 10010, 'F', 165.1, 99.99,student_self_instroduction_zhansan);
    student_init(&students[1], "王五", 10011, 'M', 175.1, 129.99,student_self_introduction);

    students[0].student_self_introduction(&students[0]);
    students[1].student_self_introduction(&students[1]);

    return 0;
}
